package mobi.hami.huapin.dao;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.HuaPin;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface HuaPinMapper extends CrudMapper<HuaPin> {

    /**
     * 获取当天拼团正在进行的信息
     * @return
     */
    @Select("select * from hua_pin where type=2 and status=1 and end_time<=now()")
    List<HuaPin> getCurrentDayHuaPinList();


    /**
     *
     * @param addressId
     * @return
     */
    @Select("select a.id,b.nick_name,b.head_photo,a.end_time\n" +
            "    ,ifnull((select  sum(sku_count)\n" +
            "      from user_order where huapin_id=a.id\n" +
            "      group by huapin_id),0) as  sku_count\n" +
            "from hua_pin a\n" +
            "left join user_info b on a.user_id=b.id\n" +
            "where a.type=2 and a.status=1 and  a.address_id=#{addressId}\n" +
            "order by sku_count, a.id desc")
    List<Map> getHuaPinByAddressId(Integer addressId);
}